package com.qianfeng.openapi.web.master.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.openapi.web.master.mapper.AdminUserMapper;
import com.qianfeng.openapi.web.master.pojo.AdminUser;
import com.qianfeng.openapi.web.master.service.AdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author LJF
 * @Date 2020/7/1 10:51
 * @Version 1.0
 */
@Service
@Transactional
public class AdminUserServiceImpl implements AdminUserService {

    @Autowired
    private AdminUserMapper adminUserMapper;

    @Override
    public AdminUser findUser(AdminUser adminUser) {
        AdminUser user = adminUserMapper.findUser(adminUser);

        if(user!=null && user.equals(adminUser)){
            return user;
        }
        return null;
    }


    @Override
    public int insertAdminUser(AdminUser adminUser) {
        return adminUserMapper.insertAdminUser(adminUser);
    }

    @Override
    public int updateAdminUser(AdminUser adminUser) {
        return adminUserMapper.updateAdminUser(adminUser);
    }

    @Override
    public int deleteAdminUser(Integer id) {
        return adminUserMapper.deleteAdminUser(id);
    }

    @Override
    public AdminUser getAdminUserById(Integer id) {
        return adminUserMapper.getAdminUserById(id);
    }

    @Override
    public PageInfo<AdminUser> getAllAdminUsers(Integer page,Integer limit) {
        PageHelper.startPage(page,limit);
        List<AdminUser> adminUserList = adminUserMapper.getAllAdminUsers();
        return new PageInfo<>(adminUserList);
    }

    @Override
    public List<AdminUser> getAdminUsers() {
        return adminUserMapper.getAllAdminUsers();
    }

    @Override
    public void deleteAdminUsers(Integer[] ids) {
        adminUserMapper.deleteAdminUsers(ids);
    }

    @Override
    public PageInfo<AdminUser> selectAdminUserByCondition(Integer page, Integer limit, String email, String realName, Integer status) {
        PageHelper.startPage(page,limit);
        List<AdminUser> adminUserList = adminUserMapper.selectAdminUserByCondition(email,realName,status);
        return new PageInfo<>(adminUserList);
    }
}
